#include "request.h"

Request::Request() : __host(""), __timestamp(0), __page("")
{
}

Request::Request(QString log)
{
    //"dawn14.cs.berkeley.edu - - [01/Jul/1995:14:35:41 -0400] "GET /history/apollo/apollo.html HTTP/1.0" 200 3258"
    //"arena.carleton.ca - - [01/Jul/1995:14:35:44 -0400] "GET / HTTP/1.0" 200 7074"
    QStringList param = log.split(" ");

    //01/06/1995:14:35:50
    QDateTime dateTime = QDateTime::fromString(replaceMonth(param.at(3)), "dd/MM/yyyy:HH:mm:ss");

    __host = param[0];
    __timestamp = dateTime.toTime_t();
    __page = param[6];
}


QString Request::host() {
    return __host;
}

int Request::timestamp() {
    return __timestamp;
}

QString Request::page() {
    return __page;
}

int Request::duration()
{
    return __duration;
}

void Request::setHost(QString host) {
    __host = host;
}

void Request::setTimestamp(int timestamp) {
    __timestamp = timestamp;
}

void Request::setPage(QString page) {
    __page = page;
}

void Request::setDuration(int duration)
{
    __duration = duration;
}

QString Request::replaceMonth(QString line) {
    return line.replace("Jan", "01").replace("Feb", "02").replace("Mar", "03").replace("Jul", "06").replace("Aug", "08").replace("[", "");
}
